<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var join = function (arr1, arr2) {
        // 数据存放位置
        const datas = {};

        for (let item of arr1) {
          update(item, datas);
        }
        for (let item of arr2) {
          update(item, datas);
        }

        // 题目要求要按id排序输出，但是实际用例没有对应打乱的用例
        return Object.values(datas).sort((a, b) => a.id - b.id);
      };

      var update = function (change, datas) {
        datas[change.id] = Object.assign(datas[change.id] ?? {}, change);
      };
    </script>
  </body>
</html>
